﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<OurSite.Web.Models.EventsModel> " %>
<%@ Import Namespace="OurSite.Business.Event"%>
<%@ Import Namespace="OurSite.Web.HTMLHelpers" %>

<script>

    $(document).ready(function()
    {
        if ($.address.value() != "/")
        {
            var eventCode = $.address.value().replace("/", "");
            $("#" + eventCode).trigger('click');
        }
    });

    $("a").click(
        function()
        {
            $.address.value($(this).attr("href"));
        });

</script>         
          
<section id="level2">				
    <header> 
        <div class="galleryHeader">
	        <h1><%= Html.Encode(ViewData["SectionTitle"])%> Events</h1> 
	    </div>
    </header> 
    <article> 
            <div class="gallery-outeritem">
   	        <%foreach (Event evt in Model.Events) { %>
   	            
   	                <div class="gallery-inneritem">
   	                    <div class="galleryThumb galleryThumbImage">
   	                        <%if (evt.SubEvents.Count > 0)
                              { %>
   	                            <a id="<%=evt.EventCode%>" href="#subevent_<%=evt.EventCode%>" rel="address:<%=evt.EventCode%>" title="<%=evt.FullLocation %>">
   	                        <% } else {
                                    string urlPath = string.Empty;
   	                                if(Model.URLPath.Contains("place/state"))
                                        urlPath = "/photos.aspx/" + Model.URLPath + "/" + evt.URLFriendly;
                                    else
                                        urlPath = "/photos.aspx/" + Model.URLPath + "/" + evt.EventCode + "/" + evt.URLFriendly;
                                  
                                  %>
   	                            <a href="<%=urlPath%>" onclick="$.address.value('/');" title="<%=evt.FullLocation %>">
   	                        <% } %>
   	                            <i style="background-image: url('<%= Model.Prefix + "Small" + evt.ListingPicture.ImagePath%>')"></i>
   	                        </a>
   	                    </div>
   	                  	
   	                  	<div class="gallery-item">
   	                  	    <table>
   	                  	        <tr>
   	                  	            <th>Event</th>
   	                  	        </tr>
   	                  	        <tr>
   	                  	            <td><%= evt.Name %> </td>
   	                  	        </tr>
   	   	                  	    <tr>
   	                  	            <th>Date</th>
   	                  	        </tr>
   	                  	        <tr>
   	                  	            <td><%= evt.StartDate.ToShortDateString()%> </td>
   	                  	        </tr>
   	                  	        <tr>
   	                  	            <th>Location</th>
   	                  	        </tr>
   	                  	        <tr>
   	                  	            <td><%= evt.City %> </td>
   	                  	        </tr>
   	                  	    </table>

   	                  	</div>    

   	                </div>
   	                
   	                <%if(evt.SubEvents.Count > 0) { %>
   	                    <div class="displayNone"><div id="subevent_<%=evt.EventCode%>">
   	                        <div class="subgalleryTitle"><%=evt.Name %> - Multiple Events</div>
                            <% foreach (Event subEvent in evt.SubEvents) { %>
   	                        <div class="subgalleryThumb subgalleryThumbImage">
   	                            <a href="/photos.aspx/<%=Model.URLPath%>/<%=subEvent.EventCode%>/<%=subEvent.URLFriendly%>">
   	                                <i style="background-image: url('<%= Model.Prefix + "Small" + subEvent.ListingPicture.ImagePath%>')"></i>
   	                                <%=subEvent.Name%>
   	                            </a>
   	                        </div>
       	                
   	                    <%} %>
   	                    </div></div>
   	                    <script>$("#<%=evt.EventCode%>").fancybox({ "autoScale": false });</script>
   	                <%  } %>
                
    	<%  } %>
    	
    	</div>
    	<div class="clear"></div>
    </article>
</section>
    
<% Html.RenderAction("PhotoMenu", "Photos"); %>

<div class="clear"></div>